home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 684 / 684.xpi / chrome / fireftp.jar / content / js / etc / dragDrop.js < prev    next >
Text File  |  2009-06-15  |  6KB  |  147 lines

  1. var dragObserver = {
  2.   origin        : null,
  3.   overName      : false,
  4.   externalFiles : new Array(),
  5.  
  6.   getSupportedFlavours : function() {
  7.     var flavours = new FlavourSet();
  8.     flavours.appendFlavour("application/x-moz-file", "nsILocalFile");
  9.     flavours.appendFlavour("text/unicode");
  10.     return flavours;
  11.   },
  12.  
  13.   onDragStart : function (event, dragData, dragAction) {
  14.     var targetID  = event.target.getAttribute('id');
  15.     this.origin   = null;
  16.     this.overName = false;
  17.  
  18.     if ((!gFtp.isConnected && targetID == 'remotetreechildren') || !treeHighlighter.dragSessionEnabled) {
  19.       return;
  20.     }
  21.  
  22.     if (targetID == 'localtreechildren' || targetID == 'remotetreechildren') {
  23.       dragData.data = new TransferData();
  24.       dragData.data.addDataForFlavour("text/unicode", targetID);
  25.       this.origin = targetID;
  26.     }
  27.   },
  28.  
  29.   onDragOver : function (event, flavour, dragSession) {
  30.     var targetID = event.target.getAttribute('id');
  31.     var row = { }; var col = { }; var child = { };
  32.  
  33.     if (gFtp.isConnected && flavour.contentType == "application/x-moz-file"
  34.                          && (targetID == 'remotetreechildren' || targetID == 'remotedirtreechildren' || targetID == 'queuetreechildren')) {
  35.       this.externalFiles = new Array();
  36.  
  37.       var transObj = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
  38.       transObj.addDataFlavor("application/x-moz-file");       // only look at files
  39.  
  40.       for (var x = 0; x < dragSession.numDropItems; ++x) {    // iterate through dragged items getting any files
  41.         try {
  42.           dragSession.getData(transObj, x);
  43.           var dataObj     = new Object();
  44.           var dropSizeObj = new Object();
  45.           transObj.getTransferData("application/x-moz-file", dataObj, dropSizeObj);
  46.  
  47.           var droppedFile = dataObj.value.QueryInterface(Components.interfaces.nsILocalFile);
  48.           this.externalFiles.push(droppedFile);
  49.         } catch (ex) {
  50.           debug(ex);
  51.           continue;
  52.         }
  53.       }
  54.  
  55.       this.origin         = "external";
  56.             if (dragSession.dataTransfer) {
  57.           dragSession.dataTransfer.effectAllowed = "all";
  58.             }
  59.     } else if (!gFtp.isConnected && flavour.contentType == "application/x-moz-file") {
  60.       this.origin         = null;
  61.             if (dragSession.dataTransfer) {
  62.           dragSession.dataTransfer.effectAllowed = "none";
  63.             }
  64.     }
  65.  
  66.         if (!dragSession.dataTransfer) {
  67.             return;
  68.         }
  69.  
  70.     if ((this.origin == 'remotetreechildren'                              && targetID == 'localtreechildren')
  71.     || ((this.origin == 'localtreechildren' || this.origin == "external") && targetID == 'remotetreechildren')) {
  72.       dragSession.dataTransfer.effectAllowed = "all";
  73.  
  74.       var x = { }; var y = { }; var width = { }; var height = { };
  75.  
  76.       if (targetID == 'localtreechildren') {
  77.         gLocalTree.treeBoxObject.getCellAt(event.pageX, event.pageY, row, col, child);
  78.         gLocalTree.treeBoxObject.getCoordsForCellItem(row.value, gLocalTree.columns["localname"], "text", x, y, width, height);
  79.         this.overName = row.value != -1 && event.pageX - gLocalTreeChildren.boxObject.x < x.value + width.value;
  80.         if (row.value != -1) {
  81.           gLocalTree.treeBoxObject.invalidateCell(row.value, gLocalTree.columns["localname"]);
  82.         }
  83.       } else {
  84.         gRemoteTree.treeBoxObject.getCellAt(event.pageX, event.pageY, row, col, child);
  85.         gRemoteTree.treeBoxObject.getCoordsForCellItem(row.value, gRemoteTree.columns["remotename"], "text", x, y, width, height);
  86.         this.overName = row.value != -1 && event.pageX - gRemoteTreeChildren.boxObject.x < x.value + width.value;
  87.         if (row.value != -1) {
  88.           gRemoteTree.treeBoxObject.invalidateCell(row.value, gRemoteTree.columns["remotename"]);
  89.         }
  90.       }
  91.     } else if (targetID == 'localdirtreechildren' || targetID == 'remotedirtreechildren') {
  92.       if (targetID == 'localdirtreechildren') {
  93.         gLocalDirTree.treeBoxObject.getCellAt(event.pageX, event.pageY, row, col, child);
  94.       } else {
  95.         gRemoteDirTree.treeBoxObject.getCellAt(event.pageX, event.pageY, row, col, child);
  96.       }
  97.  
  98.       dragSession.dataTransfer.effectAllowed = row.value != -1 ? "all" : "none";
  99.     } else if ((this.origin == 'localtreechildren' || this.origin == "remotetreechildren" || this.origin == "external") && targetID == 'queuetreechildren') {
  100.       dragSession.dataTransfer.effectAllowed = "all";
  101.     } else if (targetID == 'localtreechildren' || targetID == 'remotetreechildren') {
  102.       dragSession.dataTransfer.effectAllowed = "all";
  103.     } else {
  104.       dragSession.dataTransfer.effectAllowed = "none";
  105.     }
  106.  
  107.     if (dragSession.dataTransfer.effectAllowed == "none") {
  108.       return;
  109.     }
  110.  
  111.     // new since Firefox 3.5, XXX stoopid hack
  112.     // seems that the canDrop function of the trees doesn't affect the dragSession anymore,
  113.     // the canDrop property of the dragSession object seems to do nothing
  114.     // only effectAllowed seems to work.  So we call the tree's canDrop function manually
  115.     // and set effectAllowed appropriately
  116.  
  117.     var targetTree;
  118.     var targetTreeElement;
  119.     if (targetID == 'localtreechildren') {
  120.       targetTree = localTree;
  121.       targetTreeElement = gLocalTree;
  122.     } else if (targetID == 'localdirtreechildren') {
  123.       targetTree = localDirTree;
  124.       targetTreeElement = gLocalDirTree;
  125.     } else if (targetID == 'remotetreechildren') {
  126.       targetTree = remoteTree;
  127.       targetTreeElement = gRemoteTree;
  128.     } else if (targetID == 'remotedirtreechildren') {
  129.       targetTree = remoteDirTree;
  130.       targetTreeElement = gRemoteDirTree;
  131.     } else if (targetID == 'queuetreechildren') {
  132.       targetTree = queueTree;
  133.       targetTreeElement = gQueueTree;
  134.     } else {
  135.       dragSession.dataTransfer.effectAllowed = "none";
  136.       return;
  137.     }
  138.  
  139.     targetTreeElement.treeBoxObject.getCellAt(event.pageX, event.pageY, row, col, child);
  140.     dragSession.dataTransfer.effectAllowed = targetTree.canDrop(row.value, 0) ? "all" : "none";
  141.   },
  142.  
  143.   onDrop: function (event, dragData, dragSession) {
  144.     event.preventDefault();
  145.   }
  146. };
  147.